package com.tidb.example.demo.util;

import com.tidb.example.demo.entity.User;
import com.tidb.example.demo.mapper.UserMapper;
import com.tidb.example.demo.service.UserService;

import java.util.List;
import java.util.concurrent.CountDownLatch;

import static com.alibaba.druid.sql.ast.SQLPartitionValue.Operator.List;

/**
 * @author : ${author}
 * @version V1.0
 * @Package ${packageName}
 * @Description: todo
 * @date ${date} ${time}
 */
public class ThreadUtil extends Thread{
      private UserMapper userMapper ;
      List<User> users ;
      CountDownLatch count ;
      private int counter;

      public ThreadUtil(int counter,UserMapper userMapper, java.util.List<User> users, CountDownLatch count){
            this.userMapper = userMapper ;
            this.users = users ;
            this.count = count ;
            this.counter = counter;
      }
      @Override
      public void run() {
            System.out.println("counter : " + counter);
            //一个线程50万，每次提交1万
            long start = System.currentTimeMillis() ;
            for (int i =0 ; i< 50 ; i++) {
                  userMapper.batchSave(users) ;
            }
            long end = System.currentTimeMillis() ;
            System.out.println("插入50万耗时："+ (end-start)/1000) ;
            count.countDown();
      }
}
